//
//  YH_SettingViewController.m
//  YinHang
//
//  Created by apple on 14-9-18.
//  Copyright (c) 2014年 孙彦鹏. All rights reserved.
//

#import "YH_SettingViewController.h"
#import "UserInfoTableViewCell.h"
#import "YH_AboutUsViewController.h"
#import "YH_ChangePasswordViewController.h"
@interface YH_SettingViewController ()<UITableViewDataSource,UITableViewDelegate>{

    __weak IBOutlet UIButton *changePassword;



}

@end

@implementation YH_SettingViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setUI];
    
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBarHidden=YES;
    //设置修改密码btn圆角
    changePassword.layer.cornerRadius=5.0;
    //设置btn文字偏移
     [changePassword setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 80)];
    //设置模拟navbar的颜色
    _topView.backgroundColor= _topLabel.backgroundColor=APP_COLOR;
    //tableView属性
    _tableView.layer.cornerRadius=5.0;
    _tableView.dataSource=self;
    _tableView.delegate=self;
    _tableView.rowHeight=40;
   
    _tableView.scrollEnabled=NO;
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    //解决TableviewCell向下偏移问题
    [self.view bringSubviewToFront:_tableView];
    
    


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Custom Method
-(void)setUI{
    self.navigationItem.title = @"设置";
    
    UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 30)];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
}


#pragma mark - UITableviewDelegate Method

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;

}
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
    
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //此处引用用户信息界面的TableViewCell；
    
    static NSString *cellId = @"UserInfoTableViewCell";
    
    UserInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"UserInfoTableViewCell" owner:nil options:nil][0];
        
    }
    
    NSUInteger row = [indexPath row];
    
    NSArray *textArray=[[NSArray alloc]initWithObjects:@"清除缓存",@"检查更新",@"设置",@"关于我们",nil];
    NSArray *imageArray=[[NSArray alloc]initWithObjects:[UIImage imageNamed:@"item_64"],[UIImage imageNamed:@"item_64"],[UIImage imageNamed:@"item_64"],[UIImage imageNamed:@"item_64"],nil];
    
   
    
    UIImageView *imageView1 = (UIImageView *)[cell.contentView viewWithTag:1];
    imageView1.image=imageArray[row];
    UILabel *label2 = (UILabel *)[cell.contentView viewWithTag:2];
    label2.text=textArray[row];
    cell.contentView.backgroundColor = [UIColor whiteColor];
    return cell;

}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    indexPath = [tableView indexPathForSelectedRow];
    NSInteger row= indexPath.row;
    switch (row) {
        case 0:
        {
      
            
        }
            break;
        case 1:
        {
        }
            break;
        case 2:
        {
        }
            break;
        case 3:
        {
            YH_AboutUsViewController *au_VC=[[YH_AboutUsViewController alloc]initWithNibName:@"YH_AboutUsViewController" bundle:nil];
            [self.navigationController pushViewController:au_VC animated:YES];
         
        }
            break;
            
        default:
            break;
    }
      [tableView deselectRowAtIndexPath:indexPath animated:NO];
}
// 返回
- (void)back {
    //self.navigationController.navigationBarHidden = YES;
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)backBtnClick:(id)sender {
    
     [self.navigationController popViewControllerAnimated:YES];
    
}
- (IBAction)changePasswordBtnClick:(id)sender {
    
    YH_ChangePasswordViewController *cp_VC=[[YH_ChangePasswordViewController alloc]initWithNibName:@"YH_ChangePasswordViewController" bundle:nil];
    [self.navigationController pushViewController:cp_VC animated:YES];
    
}



@end
